﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="${ctx }/resources/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/resources/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/resources/css/style.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/resources/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${ctx }/resources/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->

<title>建材列表</title>
</head>
<body class="pos-r">
<div class="pos-a" style="width:170px; padding-left:10px; left:30;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5">
	<ul id="treeDemo" class="ztree">
	</ul>
</div>
<div style="margin-left:180px;">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 菜单管理 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="pd-20">
		<shiro:hasPermission name="sys:perm:add">
			<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a class="btn btn-success radius" href="javascript:;" onclick="add_menu('添加主菜单','${ctx}/permission/toAddMenu','700','300')"><i class="Hui-iconfont">&#xe600;</i> 添加主菜单</a></span></div>
		</shiro:hasPermission>
		<div class="mt-20">
			<table class="table table-border table-bordered table-bg table-hover table-sort">
				<thead>
					<tr>
						<th width="40">ID</th>
						<th width="60">名称</th>
						<th width="60">资源路径</th>
						<th width="60">权限编码</th>
						<th width="60">描述</th>
						<th width="100">操作</th>
					</tr>
				</thead>
				<!--每个tr 上有两个属性 cate-id='1' 当前分类id fid='0' 父级id ,顶级分类为 0，有子分类的前面加收缩图标-->
				<tbody class="x-cate">
					<c:forEach items="${dataMenu }" var="d">
					<tr class="va-m" cate-id='${d.ID}' fid='${d.PID}' >
						<td>${d.id }</td>
						<td>
							<c:if test="${d.PID!=0}">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							</c:if>

							<c:if test="${d.type=='F'}">
								<i class="Hui-iconfont x-show" status='true'>&#xe69a;</i><span>${d.name }</span></td>
							</c:if>

							<c:if test="${d.type=='O'}">
								&nbsp;&nbsp;&nbsp;&nbsp;
								${d.name }</td>
							</c:if>
						<td>${d.URL }</td>
						<td>${d.PERM_CODE }</td>
						<td>${d.DESCRIPTION }</td>
						<td class="td-manage">
							<c:if test="${d.PID==0}">
							<input class="btn btn-success radius size-MINI" onclick="location.href='${ctx }/permission/submenu/${d.id}'" type="button" value="子菜单">
							<input class="btn btn-success radius size-MINI" onclick="edit_permission('修改主菜单','${ctx }/permission/toEditMenu/${d.id}','700','300')" type="button" value="编辑">
							<shiro:hasPermission name="sys:perm:delete">
								<input class="btn btn-success radius size-MINI" onclick="location.href='${ctx }/permission/delmenu/${d.id}'" type="button" value="删除">
							</shiro:hasPermission>
							</c:if>
						</td>
					</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
	</div>
</div>
<script type="text/javascript" src="${ctx }/resources/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctx }/resources/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/js/H-ui.js"></script> 
<script type="text/javascript" src="${ctx }/resources/js/H-ui.admin.js"></script>
<script type="text/javascript">
	// 分类展开收起的分类的逻辑
	//
	$(function(){
		$("tbody.x-cate tr[fid!='0']").hide();
		// 栏目多级显示效果
		$('.x-show').click(function () {
			if($(this).attr('status')=='true'){
				$(this).html('&#xe698;');
				$(this).attr('status','false');
				cateId = $(this).parents('tr').attr('cate-id');
				$("tbody tr[fid="+cateId+"]").show();
			}else{
				cateIds = [];
				$(this).html('&#xe69a;');
				$(this).attr('status','true');
				cateId = $(this).parents('tr').attr('cate-id');
				getCateId(cateId);
				for (var i in cateIds) {
					$("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe69a;').attr('status','true');
				}
			}
		})
	})

	var cateIds = [];
	function getCateId(cateId) {
		$("tbody tr[fid="+cateId+"]").each(function(index, el) {
			id = $(el).attr('cate-id');
			cateIds.push(id);
			getCateId(id);
		});
	}

	var setting = {
	view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("tree");
			if (treeNode.isParent) {
				zTree.expandNode(treeNode);
				return false;
			} else {
				demoIframe.attr("src",treeNode.file + ".html");
				return true;
			}
		}
	}
};

var code;

function showCode(str) {
	if (!code) code = $("#code");
	code.empty();
	code.append("<li>"+str+"</li>");
}

$(document).ready(function(){
	$.post('${ctx}/menu/tree',function(data){
		var t = $("#treeDemo");
		t = $.fn.zTree.init(t, setting, eval(data));
		demoIframe = $("#testIframe");
		demoIframe.bind("load", loadReady);
		var zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.selectNode(zTree.getNodeByParam("id",'11'));
	},"html");
});


function add_menu(title,url,w,h){
	layer_show(title,url,w,h);
}
function edit_menu(title,url,w,h){
	layer_show(title,url,w,h);
}

/*图片-编辑*/
function product_edit(title,url,id){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*图片-删除*/
function product_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$(obj).parents("tr").remove();
		layer.msg('已删除!',{icon:1,time:1000});
	});
}
</script>
</body>
</html>